<template>
	<view class="pages">
		<u--textarea v-model="content" border="none" placeholder="请输入公告内容，注意控制字数哦" autoHeight></u--textarea>
		<!-- <view class="public">
			<text>发布</text>
		</view> -->
		<view class="btn_public">
			<u-button text="发布"
				customStyle="border-radius:46rpx;background:#FF7612;border:2rpx solid #FF7612;color:#fff"
				@click="submit" v-if="content.length>0"></u-button>
			<u-button type="primary" disabled text="发布"
				customStyle="border-radius:46rpx;background:#D3D4D6;border:2rpx solid #D3D4D6;color:#fff" v-else>
			</u-button>
		</view>
	</view>
</template>

<script>
	import {
		sendMessage
	} from '@/common/api.js'
	export default {
		data() {
			return {
				content: '',
			}
		},
		onLoad() {

		},
		methods: {
			submit(e) {
				let isclick = true
				if (isclick) {
					isclick = false
					uni.showLoading({
						title: '加载中'
					});

					sendMessage({
						content: this.content
					}, {
						custom: {
							auth: true,
							toast: false,
							catch: true
						}
					}).then((r) => {
						isclick = true
						uni.$u.toast('发布成功')
						setTimeout(function() {
							uni.switchTab({
								url: "/pages/index/index"
							})
						}, 2000);
						uni.hideLoading();
					}).catch((err) => {
						uni.$u.toast(err.message)
						uni.hideLoading();
					})
				}

			}

		}
	}
</script>

<style lang="scss">
	.pages {
		background-color: #fff;
		height: 100vh;

		.btn_public {
			position: fixed;
			bottom: 134rpx;
			left: 55rpx;
			right: 55rpx;
			line-height: 92rpx;
			overflow: hidden;
		}
	}
</style>
